<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .box{
            width: 300px;
            margin: 0 auto;
            margin-top: 30px;
            border: 5px solid red;
        }
        .task{
            display: flex;
            justify-content: space-around;
            margin: 10px 0;
        }
        .butn,.butns,.delete{
            width: 50px;
            height: 30px;
        }
        .todolist{
            width: 300px;
            margin: 0 auto;
            margin-top: 30px;
            border: 5px solid #000;
        }
        .task .butn{
            display: none;
        }

        p{
            font-size: 20px;
        }
    </style>
</head>
<body>
    <div class="box">
        <h2>代办清单</h2>
        <div class="main">
            <div class="task">
                <p>吃饭</p>
                <button class="butns">完成</button>
                <button class="delete">删除</button>
            </div>
            <div class="task">
                <p>睡觉</p>
                <button class="butns">完成</button>
                <button class="delete">删除</button>
            </div>
            <div class="task">
                <p>敲代码</p>
                <button class="butns">完成</button>
                <button class="delete">删除</button>
            </div>
            <div class="task">
                <p>敲代码</p>
                <button class="butns">完成</button>
                <button class="delete">删除</button>
            </div>
        </div>
        
    </div>
    <div class="todolist">
        <h2>已完成</h2>
        <div class="task-list"></div>
    </div>
    <script>
        let boxlist = document.querySelector(".box")
        let btnlist = document.querySelectorAll(".butn")
        let btnslist = document.querySelectorAll(".butns")
        let deletelist = document.querySelectorAll(".delete")
        let todolists = document.querySelector(".todolist")
        let mainlist = document.querySelector(".main")

        btnslist.forEach(function(button){
            button.onclick = function(){
                //把点击事件的父元素用一个变量装载
                let parent = button.parentNode;
                //判断完成和未完成，如果点击完成就为已完成父节点中添加一个子节点
                if(button.innerText == "完成"){
                    //点击按钮是否等于完成，如果是就在已完成父节点中挂载一个子节点
                    todolists.appendChild(parent);
                    //已完成父节点中的挂载的子节点按钮变为未完成
                    button.innerText = "未完成"
                }else{
                    mainlist.appendChild(parent)
                    button.innerText = "完成"
                }
            }
        })
        deletelist.forEach(function(button){
            button.onclick = function(){
                button.parentNode.remove();
            }
        })
    </script>
</body>
</html>